<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 输入: nums = [1, 3, 5, 6], target = 5
        // 输出: 2
        const nums = [1, 3, 5, 6];
        const target = 5
        let n;
        for (let i = 0; i < nums.length; i++) {
            let item = nums[i]
            if (item == target) {
                return n = i;
            }
             else if (target > item && target < nums[i + 1]) {
                return n = i;
            }
        };

        console.log(n);
    </script>

</body>

</html>